Skip to content

feat(secrets-manager): add environments commands and structured CLI errors - #474

Open
victorvhs017 wants to merge 3 commits into
feature/error-code-mapping-and-confirmation-helperfrom
feature/environments-commands
Open

victorvhs017 wants to merge 3 commits into
feature/error-code-mapping-and-confirmation-helperfrom
feature/environments-commands

Conversation

@victorvhs017

Copy link
Copy Markdown
Contributor

Description 📣

Secrets Management projects could be listed and created from the CLI, but there was no way to manage environments (create QA/staging, rename, soft-delete, hard-delete pending slugs) without the dashboard or raw API calls.

This branch adds infisical secrets-manager environments (alias sm) with get, create, update, and delete, wired to the existing /v1/projects/:id/environments API. Commands resolve the project from --projectId, INFISICAL_PROJECT_ID, or .infisical.yaml (except delete, which always requires explicit --projectId). They reject service tokens on these routes (machine identity or login session), surface pending deletion slugs, and use structured CLIError responses with suggested next steps for agents and scripts.

Type ✨

  • Bug fix
  • New feature
  • Improvement
  • Breaking change
  • Documentation

Tests 🛠️

  1. With a logged-in user or machine identity token, on a Secret Manager project:
    ./infisical secrets-manager environments get --projectId <project-id>
    ./infisical secrets-manager environments create cli-test --name "CLI Test" --projectId <project-id> -o json
    ./infisical secrets-manager environments update cli-test --name "CLI Test Renamed" --projectId <project-id>
    ./infisical secrets-manager environments delete cli-test --projectId <project-id> -y
  2. Confirm delete fails without --projectId even when the directory is linked.
  3. Confirm delete without -y in a TTY prompts for the slug; with -o json and no TTY, expect a structured confirmation_required error with a suggested --yes command.
  4. With INFISICAL_TOKEN set to a service token, run environments get and confirm it is ignored or rejected per flag usage (same pattern as sm projects).

- Introduced new commands for managing project environments: `create`, `update`, `delete`, and `get`.
- Enhanced error handling for environment-related operations, including checks for existing and pending environments.
- Updated `CLI.md` to document new environment error codes and command usage.
- Added unit tests to ensure functionality and error handling for the new commands.
- Integrated environment management into the existing secrets manager command structure.
@infisical-review-police

Copy link
Copy Markdown

💬 Discussion in Slack: #pr-review-cli-474-feat-secrets-manager-add-environments-commands-and-structured

Posted by Review Police — reviews, comments, new commits, and CI failures will stream into this channel.

@linear

linear Bot commented Oct 31, 2026

Copy link
Copy Markdown

ENG-5819

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Comment thread packages/cmd/environments.go Resolved
@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Critical impact] The PR appears safe to merge; no new blocking issues were found.

Summary

Adds secrets-manager environments commands to get, create, update, and delete environments.

  • The CLI can manage project environments and free slugs held by deletion.
  • Project commands share lookup and authentication helpers with environment commands.
  • Environment errors give scripts stable codes and suggested next steps.

Reviews (3) · Last reviewed commit: "fix(tests): adjust time zone handling in..." · Reviewed by Greptile

Comment thread packages/cmd/environments.go Resolved
Comment thread packages/cmd/environments.go Resolved
Comment thread packages/cmd/environments.go Resolved
Comment thread packages/cmd/environments_test.go Resolved
Comment thread packages/cmd/environments.go Resolved
- Added a new error code `invalid_flag_value` for cases where command flags are provided with invalid values, such as empty names.
- Updated `CLI.md` to document the new error code and its implications for users.
- Improved the output of environment deletion commands to clarify the timing of permanent deletions.
- Enhanced unit tests to validate the new error handling and output behavior for environment commands, ensuring robustness in CLI interactions.
Comment thread packages/cmd/environments_test.go Resolved
- Updated the `TestEnvironmentsDeleteReportsWhatHappened` test to set the local time zone to UTC, ensuring consistent date formatting across different environments.
- Added cleanup logic to restore the original local time zone after the test execution, maintaining test isolation and reliability.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant